<?php

namespace app\modules\setting\models;

use Yii;

/**
 * This is the model class for table "rbac_permissions_lut".
 *
 * @property int $permission_id
 * @property string $permission_name
 * @property string|null $description
 * @property string $crt_name
 * @property string $crt_time
 */
class PermissionsLut extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'rbac_permissions_lut';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['crt_time'], 'required'],
            [['crt_time'], 'safe'],
            [['permission_name', 'crt_name'], 'string', 'max' => 50],
            [['description'], 'string', 'max' => 252],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'permission_id' => 'Permission ID',
            'permission_name' => 'Permission Name',
            'description' => 'Description',
            'crt_name' => 'Crt Name',
            'crt_time' => 'Crt Time',
        ];
    }


    /**
     * @return array|\yii\db\ActiveRecord[]
     * @author sally
     * @date   2020-07-06
     */
    static public function getPermissionsAsList()
    {
        $permissions = PermissionsLut::find()->where(['delete_at' => 0])->all();
        $permissions = array_column($permissions, 'description', 'permission_id');

        return $permissions;
    }
}
